package com.yiwyn.async.controller;

import com.yiwyn.async.service.TaskService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;

@RestController
public class TaskController {

    private final TaskService taskService;

    public TaskController(TaskService taskService) {
        this.taskService = taskService;
    }

    @GetMapping("/test")
    public String test() throws InterruptedException, ExecutionException {
        CompletableFuture<String> hello = taskService.hello();

        CompletableFuture<Void> voidCompletableFuture = CompletableFuture.allOf(hello, hello);

        voidCompletableFuture.join();

        return hello.get();
    }

}
